<?php
include $this->Render('header.php');
?>
<link rel="stylesheet" type="text/css" href="<?php echo BASE_STYLE;?>/css/admin.css" />
<script type="text/javascript" src="<?php echo BASE_STYLE;?>/js/common.js"></script>
<script type="text/javascript" src="<?php echo BASE_STYLE;?>/js/dyhl.linkpage.js"></script>
<script type="text/javascript" src="<?php echo BASE_STYLE;?>/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="<?php echo BASE_STYLE;?>/uploadifive/jquery.uploadifive.js"></script>
<div class="tongrong-box" style="width:785px;overflow-y:scroll;overflow-x:hide;height:100%" >
	<form class="login-box-form J-ajaxForm" action="/branch/operate/option/contractsave/" method="post" autocomplete="off">
	<div class="tongrong-box-main">
    	<table width="100%" cellpadding="0" cellspacing="0" border="0">
    	    <tr>
            	<td width="90px" height="30">所属网点：</td>
                <td>
                <input type="text" name="branch_name" style="width:180px;background:#DDDDDD;" value="<?php echo $this->branch_info['br_name'];?>" readonly />
                </td>
            </tr>
        	<tr>
            	<td width="90px" height="30">合同号：</td>
                <td>
                <input type="text" name="bc_cid" style="width:280px;" value="<?php echo $this->contract_info['bc_cid']; ?>" <?php if(!empty($this->contract_info['type'])) echo 'readonly';?> />
                </td>
            </tr>
            <tr>
            	<td width="90px" height="30">合同名：</td>
                <td>
                <input type="text" name="bc_cname" style="width:280px;" value="<?php echo $this->contract_info['bc_cname'];?>" <?php if(!empty($this->contract_info['type'])) echo 'readonly';?>/>
                </td>
            </tr>
            <?php if($this->contract_info['type'] !='photo'){ ?>
            <tr>
            	<td height="70">合同摘要：</td>
                <td>
                	<textarea name="bc_details" style="resize:none; width:550px;height:420px;" <?php if(!empty($this->contract_info['type'])) echo 'readonly';?>><?php echo $this->contract_info['bc_details'];?></textarea>
                </td>
            </tr>
            <tr>
            	<td width="90px" height="30">签署日期：</td>
                <td>
                <input type="text" name="bc_date" style="width:180px;" onClick="WdatePicker()"  value="<?php echo $this->contract_info['bc_date'];?>" />
                </td>
            </tr>
            <?php }?>
        </table>
    </div>
    <?php if(!empty($this->contract_info['type'])){?>
        <form action="/branch/operate/option/contractsave/" method="post" name="form1" class="J-ajaxForm-htphoto">
        <style type="text/css">
        .ico-close {z-index:999;}
            .uploadifive-button {width:84px;height:84px !important;line-height:normal;margin-top:-84px;background:none !important;}

            .file-upload-completed,.uploadifive-queue-item {position:absolute;width:84px;bottom:0;}

            .uploadifive-queue-item .close {background: url('<?php echo BASE_STYLE;?>/uploadifive/uploadifive-cancel.png') 0 0 no-repeat;display: block;float: right;height: 16px;
                text-indent: -9999px;width: 16px;}
            .uploadifive-queue-item .progress {height: 3px;margin-top: 5px;width: 100%;}
            .uploadifive-queue-item .progress-bar {background-color: #0072BC;height: 3px;width: 0;}

            .uploadifive-queue-item .filename {display:none;}
            input[type="text"],select {background:none;}
        </style>
        <div class="order-item-box" style="margin-top:30px; border:0;">
            <fieldset style="border:1px solid #a8a8a8; padding:10px 15px;">
                <legend style="padding:5px 15px;"><h2>相关图片</h2></legend>

                    <dl class="chezixinxi-box">
                        <dt>合同照</dt>
                        <dd class="chezixinxi-pic-list J-box-order-sign">

                            <?php if(!empty($this->contract_info['bc_contract_image']['contract_image'])) foreach($this->contract_info['bc_contract_image']['contract_image'] as $k=>$v){?>
                                <div style="position:relative;display:inline-block; float:left;margin-right:10px;">
                                    <?php if($this->contract_info['type'] == 'photo'){?>
                                    <em class="ico-close J-ico-close"></em>
                                    <?php }?>
                                    <a href="<?php echo $this->contract_info['bc_contract_image']['contract_image_url'][$k];?>" data-lightbox="pic" style="position:relative; display:inline-block; width:80px;height:80px;margin-right:10px;">
                                        <img class="example-image" src="<?php echo $this->contract_info['bc_contract_image']['contract_image_thurl'][$k];?>" width="80" height="80" />
                                        <input type="hidden" value="<?php echo $v;?>" name="contract_image[]" />
                                    </a>
                                </div>
                                <?php
                            }
                            ?>

                        </dd>
                        <?php if($this->contract_info['type'] == 'photo'){?>
                        <dd>
                            <div class="file-upload-box J-file-upload-box fn-left mr10">
                                <div class="file-upload-completed" id="J_contract_img"></div>
                                <img src="<?php echo BASE_STYLE;?>/images/btn_upload_pic.png" />
                                <input type="file" id="upload_contract_img" name="upload-pic" size="30" hidefocus="true" multiple='false' accept="image/*"/>
                            </div>
                        </dd>
                        <?php }?>
                    </dl>


                <dl class="chezixinxi-box">
                        <dt>签字或盖章模板(最多一张)</dt>
                        <dd class="chezixinxi-pic-list J-box-branch-sign">

                            <?php if(!empty($this->contract_info['bc_contract_image']['sign_image'])) foreach($this->contract_info['bc_contract_image']['sign_image'] as $k=>$v){?>
                                <div style="position:relative;display:inline-block; float:left;margin-right:10px;">
                                    <?php if($this->contract_info['type'] == 'photo'){?>
                                    <em class="ico-close J-ico-close"></em>
                                    <?php }?>
                                    <a href="<?php echo $this->contract_info['bc_contract_image']['sign_image_url'][$k];?>" data-lightbox="pic" style="position:relative; display:inline-block; width:80px;height:80px;margin-right:10px;">
                                        <img class="example-image" src="<?php echo $this->contract_info['bc_contract_image']['sign_image_thurl'][$k];?>" width="80" height="80" />
                                        <input type="hidden" value="<?php echo $v;?>" name="sign_image[]" />
                                    </a>
                                </div>
                                <?php
                            }
                            ?>

                        </dd>
                        <?php if($this->contract_info['type'] == 'photo'){?>
                        <dd>
                            <div class="file-upload-box J-file-upload-box fn-left mr10">
                                <div class="file-upload-completed" id="J_sign_img"></div>
                                <img src="<?php echo BASE_STYLE;?>/images/btn_upload_pic.png" />
                                <input type="file" id="upload_sign_img" name="upload-pic" size="30" hidefocus="true" multiple='false' accept="image/*"/>
                            </div>
                        </dd>
                        <?php }?>
                    </dl>
            </fieldset>
            <?php if($this->contract_info['type'] == 'photo'){?>
                <input type="hidden" name="bcid" value="<?php echo $this->contract_info['bc_id']?>" />
                <input type="hidden" name="operate" value="photo"/>
                <input type="hidden" name="bc_date" value="<?php echo $this->contract_info['bc_date']?>"/>
                <input type="hidden" name="bc_details" value="<?php echo $this->contract_info['bc_details']?>""/>
                <input type="submit" class="a-btn-close mr15 fn-left J-contract-submit" value="保存">
                 <a class="a-btn-close J-a-btn-close fn-left" href="javascript:;">关闭</a>
            <?php }?>
        </div>

    <?php }?>
    <?php if(empty($this->contract_info['type'])){ ?>
    <div class="luru-box-btn mt50">
        <input type="hidden" name="id" value="<?php echo $this->id;?>" />
        <input type="hidden" name="bcid" value="<?php echo $this->contract_info['bc_id'];?>" />
    	<input class="btn-submit-blue fn-left mr15 J-submit" type="submit" value="提交" />
        <a class="a-btn-close J-a-btn-close" href="javascript:;">关闭</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </div>
    <?php }?>
	</form>
</div>

<script>
	//关闭弹出
	$(".J-a-btn-close").on('click',function(){
		var winElement = parent.Ext.fly(window.frameElement).up('div.x-window');
		parent.Ext.getCmp(winElement.id).close();
		
	});
	
	$(document).ready(function(e) {
		//全选
        $(".J-submit").on('click',function(){
            $(this).dyhlForm({
                beforefunction:function(){
                    $(".J-submit").prop('disabled',true);
                },
                nofunction:function(){
                    $(".J-submit").prop('disabled',false);
                },
                sucessfunction:function(data){
                    $(".J-submit").prop('disabled',false);
                    if(data['success']){
                        Ext.Msg.alert('提示','提交成功',function(){
                            window.parent.location.reload();
                            var winElement = parent.Ext.fly(window.frameElement).up('div.x-window');
                            parent.Ext.getCmp(winElement.id).close();
                        });
                        
                    }else{
                        Ext.Msg.alert('提示',data['msg']);
                    }
                }   
            }); 
        });

        $(".J-contract-submit").on('click',function(){
            $(this).dyhlForm({
                beforefunction:function(){
                    $(".J-submit").prop('disabled',true);
                },
                nofunction:function(){
                    $(".J-submit").prop('disabled',false);
                },
                sucessfunction:function(data){
                    $(".J-submit").prop('disabled',false);
                    if(data['success']){
                        Ext.Msg.alert('提示','提交成功',function(){
                            window.parent.location.reload();
                            var winElement = parent.Ext.fly(window.frameElement).up('div.x-window');
                            parent.Ext.getCmp(winElement.id).close();
                        });
                        
                    }else{
                        Ext.Msg.alert('提示',data['msg']);
                    }
                }   
            }); 
        });
			

    });
	
</script>
    <script type="text/javascript">
        <?php $timestamp = time();?>
        var names = {'contract_img':'.J-box-order-sign','sign_img':'.J-box-branch-sign'};
        function render_upload() {
            var key;
            var limit = 40;
            for (key in names) {
                var url="/order/upfile/option/upattach/";
                var fileTypeTxt = 'image/*';
                if(key =='sign_img'){
                    limit = 1 ;
                }
                $('#upload_' + key).uploadifive({
                    'auto': true,
                    'width': 84,
                    'buttonText': '',
                    'removeTimeout':1,
                    'fileObjName':'upload-pic',
                    'formData': {
                        'timestamp': '<?php echo $timestamp;?>',
                        'tb':key,
                        'filebox':'upload-pic',
                        'token': '<?php echo md5('unique_salt' . $timestamp);?>'
                    },
                    'number': key,
                    'queueClass':names[key],
                    'uploadScript': url,
                    'removeCompleted' : true,
                    'uploadLimit'     : limit,
                    'onSelect' : function(q, opt){
                        //$('#'+opt.formData.key + opt.number).find('a').remove();
                    },
                    'onUploadComplete': function (file, data, opt) {
                        var obj = $.parseJSON(data);
                        if (data == 0) {
                            alert('您上传的文件不是允许的图片文件！');
                            return;
                        };

                        if(obj['success']){

                            var html='';
                            html+='<div style="position:relative;display:inline-block; float:left;margin-right:10px;">';
                            html+=' <em class="ico-close J-ico-close">';
                            html+='</em>';
                            html+='<a href="'+obj['msg']['thumb_path']+'" data-lightbox="pic" style="position:relative; display:inline-block; width:80px;height:80px;">';
                            switch(opt.number){
                                case 'contract_img':
                                    html+=' <img class="example-image" src="'+obj['msg']['thumb_path']+'" width="80" height="80" />';
                                    html+=' <input type="hidden" value="'+obj['msg']['ai_path']+'" name="contract_image[]" />';
                                    break;
                                case 'sign_img':
                                    html+=' <img class="example-image" src="'+obj['msg']['thumb_path']+'" width="80" height="80" />';
                                    html+=' <input type="hidden" value="'+obj['msg']['ai_path']+'" name="sign_image[]" />';
                                    break;
                                }
                            html+='</a>';
                            html+='</div>';
                            console.dir(opt.queueClass);
                            $(opt.queueClass).append(html);
                        }else{
                            Ext.Msg.alert('提示',obj['msg']);
                            return false;
                        }

                    }
                });
            }
        };
        $(document).ready(function(e) {
            render_upload();
            //删除上传的图片
            $(".order-item-box").on('click','.J-ico-close',function(){
                $(this).closest('div').remove();
            });
        });
    </script>


</div>

<style type="text/css">
    .chezixinxi-box {
        overflow:hidden;
        margin-top:15px;
    }

    .chezixinxi-box dt {
        margin-bottom:10px;
    }
    .chezixinxi-box dd {
        float:left;
    }
    
    .chezixinxi-pic-list {
        margin-right:10px;
    }
    
    .chezixinxi-pic-list img {
        margin-right:10px;
    }


</style>
<?php include $this->Render('footer.php'); ?>